package com.gitee.situation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.situation.manager.SituationManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gitee.situation.service.IDomesticDataService;
import com.gitee.situation.mapper.DomesticDataMapper;
import com.gitee.situation.entity.DomesticData;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;


/**
 * DomesticData 实现层
 *
 * @Author wq
 * @Date 2021-04-06
 **/
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class DomesticDataServiceImpl extends ServiceImpl<DomesticDataMapper, DomesticData> implements IDomesticDataService {

    @Resource
    private SituationManager situationManager;

    @Override
    public void acquireDomesticData() {
        baseMapper.deleteData();
        DomesticData domesticData = situationManager.acquireDomesticData();
        if (Objects.nonNull(domesticData)) {
            save(domesticData);
        }
    }

    @Override
    public List<DomesticData> listDomesticData() {
        acquireDomesticData();
        return baseMapper.selectList(null);
    }
}